<template v-loading="load">
  <router-view/>
</template>
<script>

import {defineComponent} from "vue";
import {ElMessage, ElMessageBox, ElNotification} from "element-plus";

export default defineComponent({
  name: 'update-loading',
  data() {
    return {
      percentage: 0,
      load: false
    }
  },
  mounted() {
    window.ipcRendererApi.send('checkForUpdate')
  },
  created() {

    window.ipcRendererApi.on('download-progress', (e, data) => {
      console.log(data);
    })

    window.ipcRendererApi.on('progress', (e, data) => {
      console.log(data);
    })

    window.ipcRendererApi.on('updateMessage', (e, data) => {
      console.log(data);
      if (data.message === 'checking') {
        ElNotification({
          title: '通知',
          message: '正在检查更新',
          type: 'info'
        })
      }

      if (data.message === 'error') {
        console.log(data.error.data)
        ElNotification({
          title: '通知',
          message: '更新失败,请联系管理员',
          type: 'error'
        })
        this.load = false
      }

      if (data.message === 'downloading') {
        ElNotification({
          title: '通知',
          message: '检测到新版本,正在更新',
          type: 'info'
        })
        this.load = true
      }

      if (data.message === 'not') {
        ElNotification({
          title: '通知',
          message: '您已是最新版本!',
          type: 'success'
        })
      }
      if (data.message === 'down') {
        this.load = false
        ElMessageBox.confirm('下载更新完毕,是否更新', '提示', {
          confirmButtonText: '更新',
          cancelButtonText: '取消',
          type: 'success',
        }).then(() => {
          window.ipcRendererApi.send('start-install')
        }).catch(() => {
          ElMessage({
            type: 'success',
            message: '我们将在下一次启动时提示您',
          })
        })
      }
    })


  }
})

</script>
<style>
body {
  margin: 0;
  padding: 0;
}

#app {
  margin: 0;
  padding: 0;
}

::-webkit-scrollbar {
  width: 3px;
  height: 6px;
  background-color: #f5f5f5;
}

/*滚动条 阴影~圆角*/
::-webkit-scrollbar-track {
  -webkit-box-shadow: inset 0 0 6px rgba(128, 128, 128, 0.7);
  border-radius: 10px;
  background-color: #f5f5f5;
}

/*滑块 阴影~圆角*/
::-webkit-scrollbar-thumb {
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 6px rgba(128, 128, 128, 0.7);
  background-color: rgb(149, 147, 147);
}
</style>
